Skip to content

fix(scan): preserve whitespace in Git paths - #868

Closed
RerankerGuo wants to merge 1 commit into
alibaba:mainfrom
RerankerGuo:fix/scan-preserve-whitespace-paths
Closed

fix(scan): preserve whitespace in Git paths#868
RerankerGuo wants to merge 1 commit into
alibaba:mainfrom
RerankerGuo:fix/scan-preserve-whitespace-paths

Conversation

@RerankerGuo

Copy link
Copy Markdown
Contributor

Description

ocr scan already asks git ls-files for NUL-delimited paths, but then
applies strings.TrimSpace to every returned filename. Valid tracked files
whose names begin or end with whitespace are therefore changed before the
scanner opens them.

For example, Git returns these exact paths:

< leading.go>
<trailing.go >

The scanner previously attempted to stat leading.go and trailing.go
instead. Both lookups failed and the files silently disappeared from the scan.

This change keeps each NUL-delimited Git path exact while continuing to ignore
genuinely empty records. User-supplied ocr scan path filters retain their
existing whitespace normalization.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make check
  • make test
  • make build
  • make coverage - 90.2%, meeting the 90% threshold
  • Real temporary Git repository with leading- and trailing-space paths

Before the fix, the regression test logged two cannot stat warnings and
returned no scan items. After the fix, both files are enumerated under their
exact names. The focused test and full suite pass with the race detector.

The trailing-space fixture is skipped on Windows because the filesystem cannot
represent that filename; Windows cross-compilation remains covered by CI.

Self-review used OCR Delegation Mode with the host agent:
2/2 changed files reviewed, 0 skipped, 0 findings.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • Documentation is not required for this internal enumeration fix
  • I have signed the CLA

Related Issues

No existing issue found. All open issues, pull request text, and open pull
request changed files were checked before implementation; no competing scan
path-enumeration change was found.

Keep NUL-delimited git ls-files entries exact so valid filenames with leading or trailing whitespace remain scannable. Add a real-repository regression test for both cases.

Test: make check && make test && make build && make coverage
@github-actions

Copy link
Copy Markdown
Contributor

OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@RerankerGuo RerankerGuo closed this by deleting the head repository Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants